package com.studynotes.dev.tech.common.enums;

import cn.hutool.core.util.ReflectUtil;
import com.baomidou.mybatisplus.core.conditions.interfaces.Compare;
import com.baomidou.mybatisplus.core.conditions.interfaces.Func;
import com.baomidou.mybatisplus.core.conditions.interfaces.Join;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.lang.reflect.Method;

/**
 * @author Liu XiaoJun
 * @description: 查询方法枚举
 * @date 2025-11-07 14:51:55
 */
@Getter
@AllArgsConstructor
public enum QueryMethodEnum {

    EQ(ReflectUtil.getMethod(Compare.class, "eq", Object.class, Object.class)),
    NE(ReflectUtil.getMethod(Compare.class, "ne", Object.class, Object.class)),
    GT(ReflectUtil.getMethod(Compare.class, "gt", Object.class, Object.class)),
    GE(ReflectUtil.getMethod(Compare.class, "ge", Object.class, Object.class)),
    LT(ReflectUtil.getMethod(Compare.class, "lt", Object.class, Object.class)),
    LE(ReflectUtil.getMethod(Compare.class, "le", Object.class, Object.class)),
    BETWEEN(ReflectUtil.getMethod(Compare.class, "between", Object.class, Object.class, Object.class)),
    NOT_BETWEEN(ReflectUtil.getMethod(Compare.class, "notBetween", Object.class, Object.class, Object.class)),
    LIKE(ReflectUtil.getMethod(Compare.class, "like", Object.class, Object.class)),
    NOT_LIKE(ReflectUtil.getMethod(Compare.class, "notLike", Object.class, Object.class)),
    LIKE_LEFT(ReflectUtil.getMethod(Compare.class, "likeLeft", Object.class, Object.class)),
    LIKE_RIGHT(ReflectUtil.getMethod(Compare.class, "likeRight", Object.class, Object.class)),
    IN(ReflectUtil.getMethod(Func.class, "in", Object.class, Object[].class)),
    NOT_IN(ReflectUtil.getMethod(Func.class, "notIn", Object.class, Object[].class)),
    IS_NULL(ReflectUtil.getMethod(Func.class, "isNull", Object.class, Object[].class)),
    IS_NOT_NULL(ReflectUtil.getMethod(Func.class, "isNotNull", Object.class, Object[].class)),
    APPLY(ReflectUtil.getMethod(Join.class, "apply", String.class, Object[].class)),
    ;

    /**
     * 查询方法
     */
    private final Method method;


    /**
     * 执行方法
     *
     * @param <T>    返回对象类型
     * @param object    对象，如果执行静态方法，此值为{@code null}
     * @param args   参数对象
     * @return 结果
     */
    public <T> T invoke(Object object, Object... args) {
        return ReflectUtil.invoke(object, method, args);
    }

}
